package com.ruoyi.material.service.impl;

import java.util.List;

import com.ruoyi.material.mapper.MateriaPurchaseRecordMapper;
import com.ruoyi.workorder.domain.WorkOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.material.mapper.MateriaMapper;
import com.ruoyi.material.domain.Materia;
import com.ruoyi.material.service.IMateriaService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 材料Service业务层处理
 * 
 * @author renyuxin
 * @date 2024-05-29
 */
@Service
public class MateriaServiceImpl implements IMateriaService 
{
    @Autowired
    private MateriaMapper materiaMapper;

    @Autowired
    private MateriaPurchaseRecordMapper materiaPurchaseRecordMapper;

    /**
     * 查询材料
     * 
     * @param materiaId 材料主键
     * @return 材料
     */
    @Override
    public Materia selectMateriaByMateriaId(Long materiaId)
    {
        return materiaMapper.selectMateriaByMateriaId(materiaId);
    }

    /**
     * 查询材料列表
     * 
     * @param materia 材料
     * @return 材料
     */
    @Override
    public List<Materia> selectMateriaList(Materia materia)
    {
        return materiaMapper.selectMateriaList(materia);
    }

    /**
     * 新增材料
     * 
     * @param materia 材料
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = {Exception.class, Error.class})
    public int insertMateria(Materia materia)
    {
        return materiaMapper.insertMateria(materia);
    }

    /**
     * 修改材料
     * 
     * @param materia 材料
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = {Exception.class, Error.class})
    public int updateMateria(Materia materia)
    {
        return materiaMapper.updateMateria(materia);
    }

    /**
     * 批量删除材料
     * 
     * @param materiaIds 需要删除的材料主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = {Exception.class, Error.class})
    public int deleteMateriaByMateriaIds(Long[] materiaIds)
    {

        return materiaMapper.deleteMateriaByMateriaIds(materiaIds);
    }

    /**
     * 删除材料信息
     * 
     * @param materiaId 材料主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = {Exception.class, Error.class})
    public int deleteMateriaByMateriaId(Long materiaId)
    {
        return materiaMapper.deleteMateriaByMateriaId(materiaId);
    }

    /**
     * 查找登录用户对应的数据
     * @param materia
     * @param userId
     * @return
     */
    @Override
    public List<WorkOrder> selectMateriaListForUser(Materia materia, Long userId) {
        return materiaMapper.selectMateriaListForUser(materia,userId);
    }

    @Override
    public boolean hasData(Long[] materiaIds) {
        Long id = materiaPurchaseRecordMapper.hasData(materiaIds);
        return id!=null;
    }

    @Override
    public boolean checkNameUnique(Materia materia) {
        Long id = materiaMapper.checkNameUnique(materia);
        return id!=null;
    }

    @Override
    public List<Materia> selectMateriaListByTypeId(Long materiatypeId) {
        return materiaMapper.selectMateriaListByTypeId(materiatypeId);
    }
//    @Override
//    public boolean hasData(Long materiatypeId) {
//        return materiaMapper.selectByTypeId(materiatypeId);
//    }
}
